<?php

namespace System\Data;

/**
 * Description of Criteria
 *
 * @author elton.schivei
 */
class Criteria extends \System\Types\Object
{

    /**
     * @var Mapped
     */
    private $_mapped;

    /**
     * @var IDataDriver
     */
    private $_conn;

    /**
     * @param \System\Types\Reflections\ReflectionAssembly $class Mapped Class
     */
    public function __construct(\System\Types\Reflections\ReflectionAssembly $class)
    {
        $this->_mapped = new Mapped($class);
    }

    /**
     * @param \System\Types\Integer $id
     * @return \System\Types\Object
     */
    public function Get(\System\Types\Integer $id)
    {
        if (!$id)
            return null;

        $map = $this->_mapped;

        $sql = new \System\Types\String(<<<STR
                SELECT *
                  FROM $map->Table
                 WHERE $map->Id = ?
STR
        );

        $result = $this->_conn->Run($sql, array($id->Value()));

        $all = $result->Fetch();

        return $result->NumRows() ? $all[0] : null;
    }

}
